package primitive

import java.util.*

/**
 * Created by SEELE on 2017/7/13.
 */

fun main(args: Array<String>): Unit {
    primitive()
}

//function
fun sum(a: Int, b: Int) = a + b


fun sum1(a: Int, b: Int): Int {
    return a + b
}

fun parseInt(int: String): Int? {
    return int.toIntOrNull()
}

//primitive types
fun primitive(): Unit {
    val a: Int = 100
    var b: Long = 1000
    b = a.toLong()
    //b = a //Error 小类型往大类不能隐式转换

    b = 2000
    val str = "abc"
    val sstr = "abc and another$str"


    val array = Array(5, { i -> i * i })
    for (number in array)
        print(number)

    for (i in array.indices) {
        println("the element at $i is ${array[i]}")
    }


    for ((index, value) in array.withIndex()) {
        println("the element at $index is $value")
    }

    val intArray: IntArray = intArrayOf(1, 2, 3)

    val list = ArrayList<String>(5)
    list.add("addedItem")
}


class Person(name: String) {


    private var age: Int = 0

    private var id: String = ""

    constructor(name: String, age: Int) : this(name)

    constructor(grade: Int) : this("default_name")

    constructor(name: String, age: Int, id: String) : this(name) {
        this.age = age
        this.id = id
    }

}
